<?php
include dirname(dirname(__FILE__)).'/admin-verify.php';
include dirname(__FILE__).'/functions.php';
$arry_goods=InitArray();
$arry_class=InitClassArray();
?>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
		<title>财务管理</title>
		<?php include dirname(dirname(dirname(__FILE__))).'/include/common-header.php' ?>
		<script type="text/javascript">
		$(document).ready(function (){


			$(".number").val("0");
			var  arry_goods=<?php echo json_encode($arry_goods); ?>;
			var  arry_class=<?php echo json_encode($arry_class);?>;
			$(".number").change(function(event) {
				var re=new RegExp("^[0-9]*[1-9][0-9]*$");
				var id=$(this).attr("id");
				if (re.test($(this).val())){
				var count=$(this).parent().parent().parent().prev().html()*$(this).val();
				var total_price=$(this).parent().parent().parent().prev().prev().html()*$(this).val();
				$(this).parent().parent().parent().next().html(count);
				$(this).parent().parent().parent().next().next().html(total_price);
				arry_goods[id].count=$(this).val();
				}else{
					
					$(this).val("0");
					arry_goods[id].count=0;
					$(this).parent().parent().parent().next().html("");
				$(this).parent().parent().parent().next().next().html("");
					alert("请输入正整数");
				}

			});

			
			$("#submit-btn").click(function(event) {	
				$.post("ajax/add-form.php",{val:arry_goods,val1:arry_class},function(result,textStatus,xhr){

					if (result=="yes") {
						alert("添加成功");
						location.reload();
					}else{
						alert("添加失败");
						alert(result);
						location.reload();
					}

					});
				 
				});
		
			});

		
		</script>

</head>
<body>


	 <div class="row" style="margin-bottom: 50px;"></div>
	 <div class="container">
	<table class="table table-bordered" >
      <thead>
        <tr>
          <th>类型</th>
          <th>名称</th>
          <th>价格/箱</th>
          <th>件数/箱</th>
          <th>进货/箱</th>
          <th>数量</th>
          <th>小结</th>
        </tr>
      </thead>
      <tbody>

      	<?php
      		$i=0;
      		foreach ($arry_class as $key => $value) {
      			$cnt=$value["goods_num"];
      			if ($cnt!=0) {
      			
      			
      			echo '<tr>
    				  <td rowspan="'.$cnt.'">'.$value["class"].'</td>
    				  <td>'.$arry_goods[$i]["name"].'</td>
    				  <td>'.$arry_goods[$i]["price"].'</td>
    				  <td>'.$arry_goods[$i]["number"].'</td>
    				  <td>
    				  <div class="form-group">
				    	<div class="col-sm-5">
				      <input id="'.$i++.'"  type="number"  class="form-control normal-input number"   placeholder="每箱数量">
				  	  </div>
					  </div>
				  	</td>
    				  <td></td>
    				  <td></td>
    				  </tr>';
    				  $cnt--;
    		while ( $cnt!=0) {
    			echo '<tr>
    				  <td>'.$arry_goods[$i]["name"].'</td>
    				  <td>'.$arry_goods[$i]["price"].'</td>
    				  <td>'.$arry_goods[$i]["number"].'</td>
    				  <td> <div class="form-group">
				    	<div class="col-sm-5">
				      <input id="'.$i++.'"  type="number"  class="form-control normal-input number " placeholder="每箱数量">
				  	  </div>
					  </div></td>
    				  <td></td>
    				  <td></td>
    				  </tr>';
    				  $cnt--;
    			}
    		}


      		}




      	?>


     </tbody>
    </table>


     <div class="form-horizontal col-md-offset-3" id="add-form">
			 
			 
			  <div class="form-group">
			    <div class="col-sm-offset-2 col-sm-10">
			      <input class="btn btn-primary" id="submit-btn" type="button" value="确认录入	">
			    </div>
			  </div>
			 
	</div>
	</div>
</body>
</html>